<?php

/**
 * contact : 刘经理 19326416371
 * company : 版权所属 四川北星惯牌科技有限公司
 **/

namespace app\api\validate;

use app\common\library\Sms;
use app\common\model\CaptainApplication;
use app\common\model\StoreEmployee;
use think\Validate;

class EmployeeModify extends Validate
{
    protected $real_name;

    protected $mobile;

    /**
     * 验证规则
     */
    protected $rule = [
        'mobile'   => 'require|ruleMobile',
        'real_name'   => 'require',
        'lat'=>'require',
        'lng'=>'require',
        'address'=>'require',
    ];

    /**
     * 字段描述
     */
    protected $field = [
    ];
    /**
     * 提示消息
     */
    protected $message = [
        'mobile.require'=>'手机号不能为空',
        'mobile.ruleMobile'=>'手机号格式不正确',
        'real_name.require'=>'真实姓名不能为空',
    ];
    public function __construct(array $rules = [], $message = [], $field = [])
    {
        parent::__construct($rules, $message, $field);
    }

    protected function ruleMobile($mobile)
    {
        $this->setFiled('mobile',$mobile);
        if (!preg_match("/^1\d{10}$/", $mobile)) {
            return false;
        }
        return true;
    }

    public function checkCaptcha($captcha)
    {
        $mobile = $this->getFiled('mobile');
        if (!Sms::check($mobile, $captcha, 'employee')) {
            return false;
        }
        return true;
    }


    protected function setFiled($key,$value)
    {
        $this->$key = $value;
    }

    public function getFiled($key)
    {
        return $this->$key;
    }
}
